<template>
  <view class="menuBox">
    <view class="item" v-for="item of categoryList" :key="item.id">
      <view
        class="box"
        @click="change(item.id)"
        :class="[getItemClass(item.id)]"
      >
        {{ item.name }}
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    categoryList: {
      type: Array,
      default() {
        return [];
      },
    },
    catId: {
      type: [String, Number],
      default: undefined,
    },
  },

  data() {
    return {};
  },

  computed: {
    getItemClass() {
      return (catId) => {
        return catId === this.catId ? "active" : "";
      };
    },
  },

  methods: {
    change(id) {
      if (this.catId === id) {
        return;
      }

      this.$emit("change", id);
    },
  },
};
</script>

<style lang="scss" scoped>
.menuBox {
  overflow: hidden;

  .item {
    float: left;
    width: 25%;
    overflow: hidden;
    padding: 12rpx 14rpx;
  }

  .box {
    height: 68rpx;
    line-height: 68rpx;
    border-radius: 8rpx;
    background: #f8f8f8;
    font-size: 26rpx;
    font-weight: bold;
    color: #262626;
    text-align: center;

    &.active {
      background: #fdf1f0;
      color: #f0250e;
    }
  }
}
</style>
